Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports Microsoft.Xna.Framework
Imports Microsoft.Xna.Framework.Audio
Imports Microsoft.Xna.Framework.Content
Imports Microsoft.Xna.Framework.GamerServices
Imports Microsoft.Xna.Framework.Graphics
Imports Microsoft.Xna.Framework.Input
Imports Microsoft.Xna.Framework.Media
Imports Microsoft.Xna.Framework.Input.Touch
Imports System.IO


Public Class Flask
    Inherits Item
    Public Sub New(Content As ContentManager)

        Dim ax As New System.Xml.Serialization.XmlSerializer(ItemSequence.[GetType]())

        Dim txtReader As Stream = Microsoft.Xna.Framework.TitleContainer.OpenStream(PrinceOfPersiaGame.CONFIG_PATH_CONTENT & PrinceOfPersiaGame.CONFIG_PATH_SEQUENCES & Enumeration.Items.flask.ToString().ToUpper() & "_sequence.xml")
        'TextReader txtReader = File.OpenText(PrinceOfPersiaGame.CONFIG_PATH_CONTENT + PrinceOfPersiaGame.CONFIG_PATH_SEQUENCES + tileType.ToString().ToUpper() + "_sequence.xml");


        ItemSequence = DirectCast(ax.Deserialize(txtReader), List(Of Sequence))

        For Each s As Sequence In ItemSequence
            s.Initialize(Content)
        Next

        'Search in the sequence the right type
        Dim result As Sequence = ItemSequence.Find(Function(s As Sequence) s.name = Enumeration.StateTile.normal.ToString().ToUpper())

        If result IsNot Nothing Then
            'AMF to be adjust....
            result.frames(0).SetTexture(Content.Load(Of Texture2D)(PrinceOfPersiaGame.CONFIG_ITEMS & result.frames(0).value))

            Texture = result.frames(0).texture
        End If


        'change statetile element
        Dim stateTileElement As New StateTileElement()
        stateTileElement.state = Enumeration.StateTile.normal
        itemState.Add(stateTileElement)


        itemAnimation.PlayAnimation(ItemSequence, itemState.Value())
    End Sub
End Class
